#pragma once
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef M_PI_2
#define M_PI_2 3.14159265358979323846/2.0
#endif

#include <string>
#include <vector>
using std::string;
using std::vector;
#include "qgsgrouplayer.h"
#include "qgsvectorlayer.h"
#include "qgsrasterlayer.h"
#include <qdebug.h>


struct V8PluginData {
public:
	V8PluginData();
	~V8PluginData();
	V8PluginData(const V8PluginData& data)=delete ;

	bool init(const string v8InUrl,const string bgfilename,const string initPxFuncScript);
	

	string getV8InUrl() { return _v8InUrl; }
	string getBgFilename() { return _bgFilename; }
	bool isInited() { return _isInited; }
	bool isUseMask() { return _useMask;  }
	
	//forEachPixel script
	string getForEachPixelScript() { return _forEachPixelScript; }
	void updateForEachPixelFunc(const string newScript);

	QgsGroupLayer* rootGroupLayer() { return _rootGroupLayer; }
	QgsRasterLayer* getV8Layer() { return _v8Layer; }
	QgsVectorLayer* getMaskLayer() { return _maskLayer; }
	/// <summary>
	/// everytime roi changed use this method.
	/// </summary>
	/// <param name="feature"></param>
	void useMask(QgsFeature& feature);
	void useMaskShpFile(const QString& shpfilename);
	void removeMask();
	
	/// <summary>
	/// the object take the render's ownership. This is not very convient, use setV8LayerStyleQml instead.
	/// </summary>
	/// <param name="render"></param>
	void setV8LayerRender(QgsRasterRenderer* render);
	void setV8LayerStyleQml(string qmlfilename);
	void setV8LayerNodata(double nodata);
	void setOutlineLayerSldStyle(string sldfilename);
	void setMaskLayerSldStyle(string sldfilename);

private:
	bool _useMask;
	bool _isInited;
	string _v8InUrl;
	string _bgFilename;
	QgsGroupLayer* _rootGroupLayer;// root group layer
	QgsVectorLayer* _outlineLayer;
	QgsGroupLayer* _v8GroupLayer;
	QgsRasterLayer* _v8Layer;
	QgsVectorLayer* _maskLayer;
	QgsRasterLayer* _backgroundLayer;
	string _forEachPixelScript;
	QgsVectorLayer* _shpOutlineLayer=nullptr;
	QgsVectorLayer* _shpMaskLayer=nullptr;
	string _outlineSldFilename;
	string _maskSldFilename;
};